/**
 * 
 */
package com.obligatorio.domain.utils;

import java.math.BigInteger;
import java.security.SecureRandom;

/**
 * @author nbordenave
 * 
 */

public class CryptoUtils {

	public static String encriptarPass(String pass) throws Exception {
		String newPass = null;
		newPass = encriptar(pass);
		return newPass;
	}

	private static String encriptar(String pass) throws Exception {
		String hash = byteArrayToHexString(CryptoUtils.computeHash(pass));
		return hash;
	}

	public static byte[] computeHash(String x) throws Exception {
		java.security.MessageDigest d = null;
		d = java.security.MessageDigest.getInstance("SHA-1");
		d.reset();
		d.update(x.getBytes());
		return d.digest();
	}

	public static String byteArrayToHexString(byte[] b) {
		StringBuffer sb = new StringBuffer(b.length * 2);
		for (int i = 0; i < b.length; i++) {
			int v = b[i] & 0xff;
			if (v < 16) {
				sb.append('0');
			}
			sb.append(Integer.toHexString(v));
		}
		return sb.toString().toUpperCase();
	}

	
	// generacion de numero randomico para activar la cuenta
	public static String stringValidateAcount() {
		SecureRandom random = new SecureRandom();
		return new BigInteger(130, random).toString(32);
	}
	
	public static void main(String arg[]) {
		try {
			String input = "obligatorio";
			System.out.println(encriptarPass(input));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
